package com.heima.wemedia.config;

import com.heima.common.constants.message.PublishArticleConstants;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

@Configuration
@Slf4j
public class DeclarePubArticleRabbitConfig {


    /**
     * 定义延迟交换机
     * @return
     */
    @Bean
    public DirectExchange delayExchange(){
        return ExchangeBuilder.directExchange(PublishArticleConstants.DELAY_DIRECT_EXCHANGE)
                .delayed()     //延迟队列
                .durable(true)   //持久化
                .build();
    }


    /**
     * 定义交换机   默认持久化
     */
    @Bean
    public Queue delayQueue(){
        return new Queue(PublishArticleConstants.PUBLISH_ARTICLE_QUEUE);
    }


    /**
     * 绑定交换机和队列
     */
    @Bean
    public Binding binding(){
        return BindingBuilder.bind(delayQueue()).to(delayExchange()).with(PublishArticleConstants.PUBLISH_ARTICLE_ROUTE_KEY);
    }


}
